structure Main =
struct 

structure T=Tokens 

fun parse fname = 
    let val ins = TextIO.openIn fname
        val lexer = Mlex.makeLexer ((fn _ => TextIO.input ins),~1)
        fun loop() =
            let val token = lexer()
            in 
		print((T.toString token)^"\n");
		case token of 
		    T.EOF => ()
		  | _ => loop()
            end
    in 
        loop() before TextIO.closeIn ins
    end

fun main () =
    let fun usage () = print "Lab2 for Lexical Analysis. \nUsage:lab2 filename"
        val fileName = CommandLine.arguments ()
    in  case fileName 
         of [] => usage ()
          | [f] => parse f
          | _ => 
            (print "too many files\n"
           ; usage ())
    end


end
